//
//  PointOutView.m
//  DoctorFAQs
//
//  Created by zjq on 17/2/14.
//  Copyright © 2017年 zjq. All rights reserved.
//

#import "PointOutView.h"
static NSString * const kJHPointOutViewIdentifier = @"kJHPointOutViewIdentifier"; /**< Home界面集合视图重用标志 */
@interface PointOutView ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>{
    NSArray * _nameArray;
}
@property (nonatomic,strong) UITableView * selectTableView;
@end
@implementation PointOutView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initialzeDatas];
        [self initlizeInterface];
    }
    return self;
}
- (void)initialzeDatas {
    _nameArray = @[@"从健康档案选取",@"相册",@"相机拍照",@"取消"];
    
}
- (void)initlizeInterface {
    self.backgroundColor = [UIColor colorWithRed:28/255.0 green:28/255.0 blue:28/255.0 alpha:0.4];
    [self addSubview:self.selectTableView];
    [self addTheTap];
}

// 表格视图协议
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return _nameArray.count - 1;
    }else {
        return 1;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    }else {
        return 5*ysIZE;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kJHPointOutViewIdentifier];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = KHColorFromRGB(0xe0e0e0);
    [cell.contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(SCREEN_Width);
        make.height.offset(0.5*ysIZE);
        make.left.equalTo(cell.mas_left);
        make.bottom.equalTo(cell);
        
    }];
    if (indexPath.section == 0) {
        cell.textLabel.text  = _nameArray[indexPath.row];
    }else {
        cell.textLabel.text = _nameArray.lastObject;
        cell.textLabel.textColor = KHColorFromRGB(0x32df8f);
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.pointDeleGate &&[self.pointDeleGate conformsToProtocol:@protocol(ZJQPointOutDelegate)]) {
        [self.pointDeleGate SelectCellIndexPath:indexPath.section index:indexPath.row];
    }
}
// 灰色部分手势
- (void)addTheTap {
    UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(event:)];
    tapGesture.delegate = self;
    [self addGestureRecognizer:tapGesture];
}
- (void)event:(UITapGestureRecognizer *)gesture {
    [self removeFromSuperview];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isDescendantOfView:self.selectTableView]) {
        return NO;
    }
    return YES;
}


// lazy
- (UITableView *)selectTableView {
    if (_selectTableView) {
        return _selectTableView;
    }
    _selectTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 382*ysIZE, SCREEN_Width, 185*ysIZE) style:UITableViewStylePlain];
    _selectTableView.dataSource = self;
    _selectTableView.delegate = self;
    _selectTableView.rowHeight = 45 * ysIZE;
    _selectTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_selectTableView  registerClass:[UITableViewCell class] forCellReuseIdentifier:kJHPointOutViewIdentifier];
    return _selectTableView;
}



@end
